/***************************************************************************************
 The copyright in this software is being made available under the BSD License, included
 below. This software may be subject to other third party rights,including patent rights,
 and no such rights are granted under this license.

 Regents of the Tsinghua University, Peking University, Zhejiang University, HKUST
 Tsinghua University, Peking University, Zhejiang University, HKUST 2011

 Copyright (c) 2011, Regents of the Tsinghua University, Peking University, Zhejiang
 University, HKUST. All Rights Reserved.

 Redistribution and use in source and binary forms, with or without modification, are
 permitted provided that the following conditions are met:
   * Redistributions of source code must retain the above copyright notice,
     this list of conditions and the following disclaimer.
   * Redistributions in binary form must reproduce the above copyright notice,
     this list of conditions and the following disclaimer in the documentation
     and/or other materials provided with the distribution.
   * Neither the names of the copyright holders nor the names of its
     contributors may be used to endorse or promote products derived from this
     software without specific prior written permission.

 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
 IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
 INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
 NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
 WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
 OF SUCH DAMAGE.
***************************************************************************************/



#ifndef  _QCODER_H_
#define  _QCODER_H_

#include "global.h"

prob_state_t eq_prob_fsm[1];
prob_state_t standard_prob_fsm[113];

void qcoder_init( qcoder_env_t* qcoder, bitstream_t* currStream );
void qcoder_encode_symbol( qcoder_env_t* qcoder, prob_context_t* context, int symbol );
void qcoder_flush( qcoder_env_t* qcoder );

void aricod_encode_flag( qcoder_env_t* qcoder, prob_context_t* flag_context, int symbol );
void aricod_encode_fixed_bits( qcoder_env_t* qcoder, prob_context_t* contexts, int num_contexts, int nBits, int value );
void aricod_encode_signed_fixed_bits( qcoder_env_t* qcoder, prob_context_t* contexts, int num_contexts, int nBits, int value );
void aricod_encode_unary( qcoder_env_t* qcoder, prob_context_t* contexts, int num_contexts, int value );
void aricod_encode_signed_unary( qcoder_env_t* qcoder, prob_context_t* contexts, int num_contexts, int value );
void aricod_encode_trunary( qcoder_env_t* qcoder, prob_context_t* contexts, int num_contexts, int maxValue, int value );
void aricod_encode_expGolomb( qcoder_env_t* qcoder, prob_context_t* contexts, int num_contexts, int k, int value );
void aricod_encode_signed_expGolomb( qcoder_env_t* qcoder, prob_context_t* contexts, int num_contexts, int k, int value );


int qcoder_encode_intra_cbp( qcoder_env_t* qcoder, int cbp );
int qcoder_encode_inter_cbp( qcoder_env_t* qcoder, int cbp );
int qcoder_encode_delta_qp( qcoder_env_t* qcoder, int delta_qp );
//int qcoder_encode_eobflag(qcoder_env_t* qcoder, int eobflag);
//
int qcoder_encode_luma_16x16_coeff( qcoder_env_t* qcoder, int idx, int value, int isintra );
int qcoder_encode_luma_8x8_coeff( qcoder_env_t* qcoder, int idx, int value, int isintra );
int qcoder_encode_chroma_8x8_coeff( qcoder_env_t* qcoder, int idx, int value, int isintra );

int qcoder_encode_intra_luma_mode( qcoder_env_t* qcoder, int mode );
int qcoder_encode_intra_chroma_mode( qcoder_env_t* qcoder, int mode );
int qcoder_encode_inter_ref( qcoder_env_t* qcoder, int ref );
int qcoder_encode_mvd_y( qcoder_env_t* qcoder, int mvdy );
int qcoder_encode_mvd_x( qcoder_env_t* qcoder, int mvdx );
int qcoder_encode_mvd_y_num( qcoder_env_t* qcoder, int mvdy, int cn );
int qcoder_encode_mvd_x_num( qcoder_env_t* qcoder, int mvdx, int cn );
int qcoder_encode_inter_skiprun( qcoder_env_t* qcoder, int skiprun );
int qcoder_encode_mbtype( qcoder_env_t* qcoder, int mb_type );
int qcoder_encode_mbsubtype( qcoder_env_t* qcoder, int mb_subtype );

int qcoder_encode_inter_skip( qcoder_env_t* qcoder, int skip );
int qcoder_encode_Direction( qcoder_env_t* qcoder, int type, int direct );
int qcoder_encode_blocksize( qcoder_env_t* qcoder, int value );
int qcoder_encode_subblocksize( qcoder_env_t* qcoder, int value );
int qcoder_encode_pred_direction( qcoder_env_t* qcoder, int direction );

#endif
